package com.itheima.exer.homework.hw1011.system;

public class Foodie implements Runnable {

    private static Desk desk;

    public Foodie(Desk desk) {
        Foodie.desk = desk;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (desk.getObject()) {
                if (desk.getCount() == 0) {
                    break;
                } else {
                    if (desk.isFlag()) {
                        System.out.println("吃货吃汉堡包!!!");
                        desk.setFlag(false);
                        desk.setCount(desk.getCount() - 1);
                        desk.getObject().notifyAll();
                            /*try {
                                desk.getObject().wait();
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }*/
                    } else {
                        try {
                            desk.getObject().wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }
}
